package BookMethods;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddMethod implements BookMethods{

    @Override
    public void method(BookList booklist) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("输入书名: ");
        String bookName = scanner.nextLine();

        System.out.print("输入作者: ");
        String author = scanner.nextLine();

        System.out.print("输入价格: ");
        int price = scanner.nextInt();

        scanner.nextLine();

        System.out.print("输入类型: ");
        String type = scanner.nextLine();

        Book book = new Book(bookName, author, price, type);


        int currrentSize = booklist.getUsedSize();

        if (currrentSize == booklist.getBook().length) {
            System.out.println("书架已满，无法继续放书");
            return;
        }

        booklist.setBook(currrentSize++, book);

        booklist.setUsedSize(currrentSize);

        System.out.println("添加成功");
    }
}
